using System;
using System.Collections;
using System.Collections.Generic;
using QFramework;
using UnityEngine;

public class CoinUpgradeItem
{
    public EasyEvent OnChange = new EasyEvent();
    public bool UpgradeFinish { get; set;} = false;   //判断是升级完毕
    public string Key { get; private set;}    //用来存储的Key
    public string Description { get; private set;} //描述
    public int Price { get; private set;}    //价格
    public void Upgrade()    //升级的方法
    {
        mOnUpgrade?.Invoke(this);
        UpgradeFinish = true;
        OnChange.Trigger();
        CoinUpgradeSystem.OnCoinUpgradeSystemChange.Trigger();
    }    

    public bool ConditionCheck()    //判断是否对外显示的方法
    {
        if(mCondition != null)
        {
            return !UpgradeFinish && mCondition.Invoke(this);
        }
        return !UpgradeFinish;
    }

    private Action<CoinUpgradeItem> mOnUpgrade;    //对外配置的方法
    private Func<CoinUpgradeItem, bool> mCondition;

    /// <summary>
    /// 链式的封装
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    public CoinUpgradeItem WithKey(string key)
    {
        Key = key;
        return this;
    }

    public CoinUpgradeItem WithDescription(string description)
    {
        Description = description;
        return this;
    }

    public CoinUpgradeItem WithPrice(int price)
    {
        Price = price;
        return this;
    }

    public CoinUpgradeItem OnUpgrade(Action<CoinUpgradeItem> onUpgrade)
    {
        mOnUpgrade = onUpgrade;
        return this;
    }

    public CoinUpgradeItem Condition(Func<CoinUpgradeItem, bool> condition)
    {
        mCondition = condition;
        return this;
    }
}
